/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sys.screen;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.sql.SQLException;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.InputMap;
import javax.swing.JTable;
import javax.swing.KeyStroke;
import javax.swing.SwingConstants;
import javax.swing.SwingWorker;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import sys.bean.ClienteBean;
import sys.dao.ClienteDao;
import sys.utils.LetterUpper;
import sys.utils.Mensagens;
import sys.utils.Utils;
import static sys.utils.Utils.cpfCnpjCorreto;
import static sys.utils.Utils.escClose;
import static sys.utils.Utils.foneCorreto;

/**
 *
 * @author Cesar Daniel
 */
public class UIPesquisaCliente extends javax.swing.JDialog {

    private UIRelatorioClientes relClientes;
    private UIVale vMercadoria;
    private UIProdutosCliente prodCliente;
    private UICobrancaCliente cobCliente;
    private UIAlteraVale AlteraVale;
    private CPedidosParaEntrega cPedidosEntrega;
    /*
     se tela for igual a 0 esta vindo da tela de relatorio cliente
     sete tela for igual a 1 esta vindo da tela de vale mercadoria
     */
    int tela;

    public UIPesquisaCliente(UIRelatorioClientes parent, boolean modal) {
        super(parent, modal);
        relClientes = parent;
        initComponents();
        setLocationRelativeTo(null);
        setResizable(false);
        this.setIconImage(new ImageIcon(getClass().getResource("/sys/picture/icon.png")).getImage());
        UIManager.put("Table.alternateRowColor", new java.awt.Color(230, 255, 255));
        escClose(this);
        txCliente.requestFocus();
        tela = 0;
    }

    public UIPesquisaCliente(UIVale parent, boolean modal) {
        super(parent, modal);
        vMercadoria = parent;
        initComponents();
        setLocationRelativeTo(null);
        setResizable(false);
        this.setIconImage(new ImageIcon(getClass().getResource("/sys/picture/icon.png")).getImage());
        UIManager.put("Table.alternateRowColor", new java.awt.Color(230, 255, 255));
        escClose(this);
        txCliente.requestFocus();
        tela = 1;
    }

    public UIPesquisaCliente(UIProdutosCliente parent, boolean modal) {
        super(parent, modal);
        prodCliente = parent;
        initComponents();
        setLocationRelativeTo(null);
        setResizable(false);
        this.setIconImage(new ImageIcon(getClass().getResource("/sys/picture/icon.png")).getImage());
        UIManager.put("Table.alternateRowColor", new java.awt.Color(230, 255, 255));
        escClose(this);
        txCliente.requestFocus();
        tela = 2;
    }

    public UIPesquisaCliente(UICobrancaCliente parent, boolean modal) {
        super(parent, modal);
        cobCliente = parent;
        initComponents();
        setLocationRelativeTo(null);
        setResizable(false);
        this.setIconImage(new ImageIcon(getClass().getResource("/sys/picture/icon.png")).getImage());
        UIManager.put("Table.alternateRowColor", new java.awt.Color(230, 255, 255));
        escClose(this);
        txCliente.requestFocus();
        tela = 3;
    }

    public UIPesquisaCliente(UIAlteraVale parent, boolean modal) {
        super(parent, modal);
        AlteraVale = parent;
        initComponents();
        setLocationRelativeTo(null);
        setResizable(false);
        this.setIconImage(new ImageIcon(getClass().getResource("/sys/picture/icon.png")).getImage());
        UIManager.put("Table.alternateRowColor", new java.awt.Color(230, 255, 255));
        escClose(this);
        txCliente.requestFocus();
        tela = 4;
    }

    public UIPesquisaCliente(CPedidosParaEntrega parent, boolean modal) {
        super(parent, modal);
        cPedidosEntrega = parent;
        initComponents();
        setLocationRelativeTo(null);
        setResizable(false);
        this.setIconImage(new ImageIcon(getClass().getResource("/sys/picture/icon.png")).getImage());
        UIManager.put("Table.alternateRowColor", new java.awt.Color(230, 255, 255));
        escClose(this);
        txCliente.requestFocus();
        tela = 5;
    }

    private void atualizaTabela() {
        DefaultTableModel modelo = (DefaultTableModel) tabela.getModel();
        modelo.setNumRows(0);

        try {
            for (ClienteBean cliente : ClienteDao.getListaClientes(txConsulta())) {
                modelo.addRow(new Object[]{
                    cliente.getCodigo(), cliente.getNome(), foneCorreto(cliente.getDddFone(), cliente.getFone()), cliente.getDescCidade(), cpfCnpjCorreto(cliente.getCpfCnpj()), cliente.getRgIe(), cliente.getSituacao()
                });
            }
        } catch (SQLException | IOException ex) {
            Mensagens.msgErro("erro\n" + ex.getMessage());
        }
        tabela.requestFocus();
        tabela.changeSelection(0, 5, false, false);

        DefaultTableCellRenderer centralizado = new DefaultTableCellRenderer();
        centralizado.setHorizontalAlignment(SwingConstants.CENTER);

        tabela.getColumnModel().getColumn(0).setCellRenderer(centralizado);
        tabela.getColumnModel().getColumn(2).setCellRenderer(centralizado);
        tabela.getColumnModel().getColumn(4).setCellRenderer(centralizado);
        tabela.getColumnModel().getColumn(5).setCellRenderer(centralizado);

    }

    private void selCliente() {

        if (tela == 0) {
            this.relClientes.txCodigo.setText(tabela.getValueAt(tabela.getSelectedRow(), 0).toString());
            this.relClientes.limpaCampos();
            this.relClientes.geraRelatorio();
            this.dispose();
        }

        if (tela == 1) {
            this.vMercadoria.txCodCliente.setText(tabela.getValueAt(tabela.getSelectedRow(), 0).toString());
            this.vMercadoria.preencheCampos();
            this.dispose();
        }

        if (tela == 2) {
            this.prodCliente.txCodigoCliente.setText(tabela.getValueAt(tabela.getSelectedRow(), 0).toString());
            this.prodCliente.preencheCampos();
            this.dispose();
        }

        if (tela == 3) {
            this.cobCliente.txCodigoCliente.setText(tabela.getValueAt(tabela.getSelectedRow(), 0).toString());
            this.cobCliente.preencheCampos();
            this.dispose();
        }
        if (tela == 4) {
            this.AlteraVale.txNovoCodigoCliente.setText(tabela.getValueAt(tabela.getSelectedRow(), 0).toString());
            this.AlteraVale.preencheCampos();
            this.dispose();
        }
        if (tela == 5) {
            this.cPedidosEntrega.txCodigoCliente.setText(tabela.getValueAt(tabela.getSelectedRow(), 0).toString());
            this.cPedidosEntrega.txNomeCliente.setText(tabela.getValueAt(tabela.getSelectedRow(), 1).toString());
            this.dispose();
        }

    }

    private String tipoConsulta() {
        String tipo = "";

        if (jcbNome.isSelected()) {
            tipo = "C05NOME";
        }
        if (jcbCpf.isSelected()) {
            tipo = "C05CPFCGC";
        }
        if (jcbRg.isSelected()) {
            tipo = "C05RGINSC";
        }
        if (jcbCodigo.isSelected()) {
            tipo = "C05CODIGO";
        }
        return tipo;
    }

    private String txConsulta() {
        if (jcbPesContenha.isSelected()) {

            String pParte = "";
            String uParte = "";
            String tx = Utils.removerAcento(txCliente.getText().replace(".", "").replace("/", "").replace("-", ""));

            String[] sql = tx.split(" ");

            int cont = 0;
            for (String s : sql) {
                if (cont == 0) {
                    pParte += "WHERE " + tipoConsulta() + " LIKE '%" + s + "%' ";
                }
                if (cont > 0) {
                    uParte += "AND " + tipoConsulta() + " LIKE '%" + s + "%'";
                }
                cont++;
            }
            return pParte + uParte;

        } else {
            return "WHERE " + tipoConsulta() + " LIKE '" + txCliente.getText().replace(".", "").replace("/", "").replace("-", "") + "%'";
        }
    }

    private boolean validaInfo() {
        boolean v = true;
        String msg = "Selecione pelo menos uma opção de pesquisa.";

        if (jcbNome.isSelected() || jcbCodigo.isSelected()
                || jcbCpf.isSelected() || jcbRg.isSelected()) {
        } else {
            v = false;
        }
        if (jcbPesContenha.isSelected() || jcbPesIncremental.isSelected()) {
        } else {
            v = false;
        }
        if (v == false) {
            Mensagens.msgAtencao(msg);
        }
        return v;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabela = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        txCliente = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jcbPesIncremental = new javax.swing.JCheckBox();
        jcbPesContenha = new javax.swing.JCheckBox();
        jPanel5 = new javax.swing.JPanel();
        jcbNome = new javax.swing.JCheckBox();
        jcbCpf = new javax.swing.JCheckBox();
        jcbRg = new javax.swing.JCheckBox();
        jcbCodigo = new javax.swing.JCheckBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("PESQUISAR CLIENTES");

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        tabela.setAutoCreateRowSorter(true);
        tabela.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        tabela.setForeground(new java.awt.Color(51, 51, 255));
        tabela.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "CODIGO", "NOME", "TELEFONE", "CIDADE", "CPF/CNPF", "RG/I.E.", "SITUACAO"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabela.setGridColor(new java.awt.Color(204, 204, 204));
        tabela.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(tabela);
        if (tabela.getColumnModel().getColumnCount() > 0) {
            tabela.getColumnModel().getColumn(0).setPreferredWidth(30);
            tabela.getColumnModel().getColumn(1).setPreferredWidth(200);
            tabela.getColumnModel().getColumn(2).setPreferredWidth(40);
            tabela.getColumnModel().getColumn(6).setMinWidth(0);
            tabela.getColumnModel().getColumn(6).setPreferredWidth(0);
            tabela.getColumnModel().getColumn(6).setMaxWidth(0);
        }
        InputMap im = tabela.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
        KeyStroke enter = KeyStroke.getKeyStroke("ENTER");

        im.put (enter, im.get
            (KeyStroke.getKeyStroke(KeyEvent.VK_GREATER, 0)));
        Action enterAction = new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                JTable tabela = (JTable) e.getSource();
                selCliente();
            }

        };

        tabela.getActionMap ()

        .put(im.get(enter), enterAction);
        tabela.addMouseListener ( new MouseAdapter(){

            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    selCliente();
                }
            }
        }
    );

    jPanel2.setBackground(new java.awt.Color(255, 255, 255));
    jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "OPÇÕES:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 10))); // NOI18N

    txCliente.setDocument(new LetterUpper());
    txCliente.setBackground(new java.awt.Color(245, 245, 245));
    txCliente.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
    txCliente.setForeground(new java.awt.Color(51, 51, 255));
    txCliente.setBorder(null);
    txCliente.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            txClienteActionPerformed(evt);
        }
    });

    jLabel1.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
    jLabel1.setText("NOME CLIENTE:");

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel2Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(txCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 558, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel1))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    jPanel2Layout.setVerticalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel2Layout.createSequentialGroup()
            .addComponent(jLabel1)
            .addGap(5, 5, 5)
            .addComponent(txCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    jPanel3.setBackground(new java.awt.Color(255, 255, 255));
    jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "PESQUISA", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 10))); // NOI18N

    jcbPesIncremental.setBackground(new java.awt.Color(255, 255, 255));
    jcbPesIncremental.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
    jcbPesIncremental.setText("INCREMENTAL");
    jcbPesIncremental.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jcbPesIncrementalActionPerformed(evt);
        }
    });

    jcbPesContenha.setBackground(new java.awt.Color(255, 255, 255));
    jcbPesContenha.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
    jcbPesContenha.setSelected(true);
    jcbPesContenha.setText("CONTENHA");
    jcbPesContenha.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jcbPesContenhaActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
    jPanel3.setLayout(jPanel3Layout);
    jPanel3Layout.setHorizontalGroup(
        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jcbPesIncremental)
            .addContainerGap())
        .addGroup(jPanel3Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jcbPesContenha)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    jPanel3Layout.setVerticalGroup(
        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jcbPesContenha, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jcbPesIncremental, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap())
    );

    jPanel5.setBackground(new java.awt.Color(255, 255, 255));
    jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "PESQUISA", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 10))); // NOI18N

    jcbNome.setBackground(new java.awt.Color(255, 255, 255));
    jcbNome.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
    jcbNome.setSelected(true);
    jcbNome.setText("NOME");
    jcbNome.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jcbNomeActionPerformed(evt);
        }
    });

    jcbCpf.setBackground(new java.awt.Color(255, 255, 255));
    jcbCpf.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
    jcbCpf.setText("CPF/CNPJ");
    jcbCpf.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jcbCpfActionPerformed(evt);
        }
    });

    jcbRg.setBackground(new java.awt.Color(255, 255, 255));
    jcbRg.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
    jcbRg.setText("RG/I.E.");
    jcbRg.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jcbRgActionPerformed(evt);
        }
    });

    jcbCodigo.setBackground(new java.awt.Color(255, 255, 255));
    jcbCodigo.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
    jcbCodigo.setText("CODIGO");
    jcbCodigo.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jcbCodigoActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
    jPanel5.setLayout(jPanel5Layout);
    jPanel5Layout.setHorizontalGroup(
        jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel5Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel5Layout.createSequentialGroup()
                    .addComponent(jcbRg)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(jPanel5Layout.createSequentialGroup()
                    .addComponent(jcbNome)
                    .addGap(8, 8, 8)))
            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jcbCpf)
                .addComponent(jcbCodigo))
            .addContainerGap())
    );
    jPanel5Layout.setVerticalGroup(
        jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jcbNome, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jcbCpf, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jcbRg, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jcbCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap())
    );

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 895, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addContainerGap())
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
            .addGap(11, 11, 11)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 327, Short.MAX_VALUE)
            .addContainerGap())
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGap(0, 0, 0))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );

    pack();
    }// </editor-fold>//GEN-END:initComponents

    private void buscaCliente() {
        final BarraProgresso pb = new BarraProgresso(this);
        SwingWorker worker = new SwingWorker() {

            @Override
            protected Object doInBackground() throws Exception {
                pb.gerarJanela();
                pb.lbDescricao.setText("BUSCANDO, POR FAVOR AGUARDE...");
                atualizaTabela();
                return null;
            }

            @Override
            protected void done() {
                pb.fechar();
            }
        };
        worker.execute();

    }
    private void jcbNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbNomeActionPerformed
        jcbCpf.setSelected(false);
        jcbRg.setSelected(false);
        jcbCodigo.setSelected(false);
        txCliente.requestFocus();
        txCliente.selectAll();
    }//GEN-LAST:event_jcbNomeActionPerformed

    private void jcbCpfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbCpfActionPerformed
        jcbNome.setSelected(false);
        jcbRg.setSelected(false);
        jcbCodigo.setSelected(false);
        txCliente.requestFocus();
        txCliente.selectAll();
    }//GEN-LAST:event_jcbCpfActionPerformed

    private void jcbRgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbRgActionPerformed
        jcbCpf.setSelected(false);
        jcbNome.setSelected(false);
        jcbCodigo.setSelected(false);
        txCliente.requestFocus();
        txCliente.selectAll();
    }//GEN-LAST:event_jcbRgActionPerformed

    private void jcbCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbCodigoActionPerformed
        jcbCpf.setSelected(false);
        jcbRg.setSelected(false);
        jcbNome.setSelected(false);
        txCliente.requestFocus();
        txCliente.selectAll();
        txCliente.selectAll();
    }//GEN-LAST:event_jcbCodigoActionPerformed

    private void jcbPesIncrementalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbPesIncrementalActionPerformed
        jcbPesContenha.setSelected(false);
        txCliente.requestFocus();
        txCliente.selectAll();
    }//GEN-LAST:event_jcbPesIncrementalActionPerformed

    private void jcbPesContenhaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbPesContenhaActionPerformed
        jcbPesIncremental.setSelected(false);
        txCliente.requestFocus();
        txCliente.selectAll();
    }//GEN-LAST:event_jcbPesContenhaActionPerformed

    private void txClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txClienteActionPerformed
        buscaCliente();
    }//GEN-LAST:event_txClienteActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JCheckBox jcbCodigo;
    private javax.swing.JCheckBox jcbCpf;
    private javax.swing.JCheckBox jcbNome;
    private javax.swing.JCheckBox jcbPesContenha;
    private javax.swing.JCheckBox jcbPesIncremental;
    private javax.swing.JCheckBox jcbRg;
    private javax.swing.JTable tabela;
    private javax.swing.JTextField txCliente;
    // End of variables declaration//GEN-END:variables
}
